package test07;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {

        //建立链接
        Socket socket = new Socket("127.0.0.1", 40000);

        //传输数据
        BufferedInputStream bufferedInputStream = new BufferedInputStream(
                new FileInputStream("D:\\27162\\Desktop\\itheima\\untitled\\girl.jpg")
        );
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(socket.getOutputStream());
        int len;
        byte[] bytes = new byte[1024];
        while ((len = bufferedInputStream.read(bytes)) != -1) {
            bufferedOutputStream.write(bytes, 0, len);
        }

        //结束标志,表示传输完成
        socket.shutdownOutput();
        //接收回显数据
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(socket.getInputStream())
        );
        String s = bufferedReader.readLine();
        System.out.println(s);
        //断开链接
        socket.close();

    }
}
